<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
    <add-modal ref="addModalRef"></add-modal>
  </div>
</template>
<script setup>
import { ref, reactive ,provide} from 'vue'
import ruleEvent from '@/api/logistics/ruleEvent'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'
import AddModal from "./addModal.vue";
import dictHelp from "@/utils/dicthelp.js";
const crudRef = ref()
const addModalRef = ref()


const switchStatus = (statusValue, id, statusName) => {
  ruleEvent.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const addOpenPage = (data)=>{
  addModalRef.value.open(data)
}

const options = reactive({
  id: 'rule_event',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: ruleEvent.getList,
  recycleApi: ruleEvent.getRecycleList,
  beforeOpenAdd:()=>{
    addOpenPage()
    return false
  },
  add: {
    show: true,
    api: ruleEvent.save,
    auth: ['logistics:ruleEvent:save'],
  },
  beforeOpenEdit:(record)=>{
    addOpenPage(record)
    return false
  },
  edit: {
    show: true,
    api: ruleEvent.update,
    auth: ['logistics:ruleEvent:update']
  },
  delete: {
    show: true,
    api: ruleEvent.deletes,
    auth: ['logistics:ruleEvent:delete'],
    realApi: ruleEvent.realDeletes,
    realAuth: ['logistics:ruleEvent:realDeletes']
  },
  recovery: {
    show: true,
    api: ruleEvent.recoverys,
    auth: ['logistics:ruleEvent:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
      title: "服务",
      dataIndex: "service_id",
      formType: "select",
      virtualListProps:{},
      dict: dictHelp.service,
  },
  {
    title: "是否忽略其他规则",
    dataIndex: "ignore",
    formType: "select",
    dict:{
        data:[{label:'是',value:"1"},{label:'否',value:"0"}],
        translation: true,
    },
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "radio",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    dict: {
      data: [
        {
          label: "正常",
          value: "1"
        },
        {
          label: "停用",
          value: "0"
        }
      ],
      translation: true
    }
  },
  {
    title: "满足条件",
    dataIndex: "where_type",
    formType: "radio",
    commonRules: {
      required: true,
      message: "请输入满足条件"
    },
    dict: {
      name:'EventWhere',
      translation: true
    }
  },
  {
    title: "优先级",
    dataIndex: "level",
    formType: "input"
  },
  {
    title: "逻辑",
    dataIndex: "logic",
    formType: "input",
    hide:true,
  },
  {
    title: "动作",
    dataIndex: "action",
    formType: "input",
    hide: true
  },
  {
    title: "费用",
    dataIndex: "fee",
    formType: "input",
    hide: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
      title: "费用类型",
      dataIndex: "fee_type",
      formType: "select",
      dict:{
          url: 'finance/feeType/list',
          props: {label: 'fee_name', value: 'id'},
          params:{
            select:'id,fee_name'
          },
          translation: true,
      },
      hide:true,
  },
  {
      title: "",
      dataIndex: "fee_check",
      formType: "checkbox",
      dict:{
          data:[{label:'应收',value:"1"},{label:'应付',value:"2"},{label:'销售成本',value:"3"}],
          translation: true,
      },
      hide:true,
  },
  {
      title: "单位",
      dataIndex: "fee_charge_type",
      dict:{
          name: 'ChargeType',
          translation: true,
      },
      formType: "select",
      hide:true,
  },
  {
      title: "币种",
      dataIndex: "currencytype",
      dict:{
          name: 'currencyType',
          translation: true,
      },
      formType: "select",
      hide:true,
  },

])
provide('crudRef', crudRef)
</script>
<script> export default { name: 'logistics:ruleEvent' } </script>